<template>
  <!--    简历诊断历史页面     -->
  <page-wrap back title="历史报告" hideTab stayStill :hideSafeArea="true">
    <view class="allContainer">
      <view class="unLockNumberBox">剩余解锁次数:{{ unLockNum }}</view>

      <diagnosisHistoryItem
        v-for="(item, index) in list"
        :index="index"
        :key="index"
        :itemObj="item"
      />
      <u-loadmore
        v-if="list.length > 0 || !loaded"
        class="list-more"
        :status="moreLoading"
        :load-text="loadText"
      />
      <Empty
        v-if="loaded && list.length <= 0"
        :baseImg="emptyImg"
        text="暂无数据"
        :fontWeight="400"
      />
    </view>
  </page-wrap>
</template>

<script>
import Empty from "@/components/Empty.vue";
import diagnosisHistoryItem from "./diagnosisHistoryItem.vue";
import { getPageResumeDiagnoseRecord, getLeftUnlockNum } from "@/api/index"; 
import { showDelayToastTip } from "@/utils/handle";
export default {
  components: {
    Empty,
    diagnosisHistoryItem,
  },
  
  data() {
    return {
      emptyImg: this.$imgBaseSelf + "common/empty.png",
      moreLoading: "loadmore",
      screenHeight: 0,
      screenWidth: 0,
      containerHeight: 0,
      loadText: {
        loadmore: "加载更多",
        loading: "加载中",
        nomore: "已经到底啦",
      },
      pageParams: {
        pageNo: 1,
        pageSize: 15,
      },
      loaded: false,
      list: [],
      unLockNum: 0,

      // 测试
      //personId: "24192616",
      personId: uni.getStorageSync("person-id").slice(2) || undefined,
      openId: uni.getStorageSync("openid"),
      companyId: uni.getStorageSync("company-id"),
    };
  },

  mounted() {
    this.getData(false);
    //this.reqGetLeftUnlockNum();
  },
  onReady() {
    let systemInfo = uni.getSystemInfoSync();
    this.screenHeight = systemInfo.windowHeight;
    this.screenWidth = systemInfo.windowWidth;
  },

  onPullDownRefresh() {
    this.getData(false);
    this.reqGetLeftUnlockNum();
    uni.stopPullDownRefresh();
  },

  onShow(){ 
    this.reqGetLeftUnlockNum();
  },

  // 监听页面滚动到底部
  onReachBottom() {
    this.loadMore();
  },

  methods: {
    // 获取剩余解锁次数
    reqGetLeftUnlockNum() {
      const params = {
        personId: this.personId,
      };
      console.log(params);
      getLeftUnlockNum(params)
        .then((res) => {
         // console.log(res);
          if (res.code == 200) {
            this.unLockNum = res.data;
          } else {
            showDelayToastTip(res.status_desc, 0);
          }
        })
        .catch((e) => {
          console.log(e);
        });
    },

    loadMore() {
      this.getData(true);
    },

    getData(isMore) {
      if (
        !this.personId ||
        this.moreLoading == "loading" ||
        (this.moreLoading == "nomore" && isMore)
      ) {
        return;
      }

      if (!isMore) {
        // 刷新数据
        this.pageParams.pageNo = 1;
        console.log("刷新简历评定历史列表");
      }
      const params = {
        pageNo: this.pageParams.pageNo,
        pageSize: this.pageParams.pageSize,
        personId: this.personId,
      };
      this.moreLoading = "loading";
      //console.log(params);
      getPageResumeDiagnoseRecord(params)
        .then((res) => {
          this.moreLoading = "loadmore";
          this.loaded = true;
          //console.log(res);
          if (res.code == 200) {
            if (isMore) {
              this.list.push(...res.data);
            } else {
              this.list = res.data;
            }

            this.pageParams.pageNo++;
            if (this.pageParams.pageNo > res.pageparam.pages) {
              this.moreLoading = "nomore";
            }
          } else {
            this.moreLoading = "nomore";
            uni.showToast({
              title: res.status_desc,
              icon: "none",
            });
          }
        })
        .catch((e) => {
          console.log(e);
          this.moreLoading = "nomore";
        })
        .finally(() => {});
    },
  },
};
</script>
<style  lang="scss" scoped>
// .allContainer{
//   flex-grow: 1;
//   display: flex;
//   flex-direction: column;
//   height: 100%;

//   .scrollView{
//     box-sizing: border-box;
//     height: 1px;
//     flex-grow: 1;
//   }
// }

.unLockNumberBox {
  padding-top: 16rpx;
  padding-bottom: 16rpx;
  text-align: right;
  margin-right: 16rpx;
}
</style>